package com.xuzimian.globaldemo.mq.rabbitmq.util;

import java.io.IOException;
import java.util.concurrent.TimeoutException;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.xuzimian.globaldemo.mq.rabbitmq.constants.Config;

/**
 * @Description rabbitmq 客户端帮助类
 * @author xzm
 */
public class MqUtil {

    /**
     * @Description 创建一个原生的RabbitMq AMQP协议的连接对象
     * 
     * @return
     * @throws TimeoutException
     * @throws IOException
     */
    public static Connection createSingletonConnection() throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setUsername(Config.MQServerConect.USERNAME);
        factory.setPassword(Config.MQServerConect.PASSWORD);
        factory.setVirtualHost(Config.MQServerConect.VIRTUALHOST_DEFAULT);
        factory.setHost(Config.MQServerConect.HOST);
        factory.setPort(Config.MQServerConect.PORT_AMQP);
        return factory.newConnection();
    }

    public static Connection createSingletonConnection2() throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setUsername("autdquote_mqtt_dy");
        factory.setPassword("autdquote_mqtt_dyPwd");
        factory.setVirtualHost("/autdquote5");
        factory.setHost("");
        factory.setPort(10101);
        return factory.newConnection();
    }

}